#include "global.h"
#include <string.h>

/* 全局配置变量定义 */
GlobalConfig g_config;

void init_global_config(void) {
    /* 初始化网络配置 */
    g_config.port = DEFAULT_PORT;
    strncpy(g_config.server_ip, DEFAULT_SERVER_IP, sizeof(g_config.server_ip)-1);
    
    /* 初始化数据库配置 */
    strncpy(g_config.db_path, DEFAULT_DB_PATH, sizeof(g_config.db_path)-1);
    g_config.retention_days = DATA_RETENTION_DAYS;
    
    /* 初始化传感器配置 */
    g_config.read_interval = SENSOR_READ_INTERVAL;
    strncpy(g_config.sensor_id, DEFAULT_SENSOR_ID, sizeof(g_config.sensor_id)-1);
    
    /* 初始化日志配置 */
    strncpy(g_config.log_file, LOG_FILE, sizeof(g_config.log_file)-1);
    g_config.log_level = LOG_LEVEL;
    g_config.log_max_size = LOG_MAX_SIZE;
    g_config.log_lock_enabled = LOG_LOCK_ENABLED;
}

void print_global_config(void) {
    printf("=== Global Configuration ===\n");
    printf("Network:\n");
    printf("  Port: %d\n", g_config.port);
    printf("  Server IP: %s\n", g_config.server_ip);
    
    printf("\nDatabase:\n");
    printf("  DB Path: %s\n", g_config.db_path);
    printf("  Data Retention Days: %d\n", g_config.retention_days);
    
    printf("\nSensor:\n");
    printf("  Read Interval: %d seconds\n", g_config.read_interval);
    printf("  Sensor ID: %s\n", g_config.sensor_id);
    
    printf("\nLogging:\n");
    printf("  Log File: %s\n", g_config.log_file);
    printf("  Log Level: %d\n", g_config.log_level);
    printf("  Log Max Size: %ld bytes\n", g_config.log_max_size);
    printf("  Log Lock Enabled: %s\n", g_config.log_lock_enabled ? "true" : "false");
    printf("============================\n");
}